package com.example.demo.config;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class String2DateConverter implements Converter<String, Date>{

	@Override
	public Date convert(String source) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return format.parse(source);
		} catch (ParseException e) {
			throw new RuntimeException("日期格式不对,请参照：1999-12-10这个格式来设置");
		}
	}

}
